package com.zmn.oms.services.impl.conf.ordertag;

import com.zmn.common.utils.date.DateUtil;
import com.zmn.oms.model.entity.conf.ordertag.ConfOrderTagCategory;
import com.zmn.oms.model.entity.conf.ordertag.ConfOrderTagCategoryQuery;
import com.zmn.oms.persistence.interfaces.conf.ordertag.ConfOrderTagCategoryDao;
import com.zmn.oms.services.interfaces.conf.ordertag.ConfOrderTagCategoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 类描述：工单标记分类
 *
 * @author liuying
 * @date 2021/08/30 16:09
 */
@Service
public class ConfOrderTagCategoryServiceImpl implements ConfOrderTagCategoryService {

    @Resource
    private ConfOrderTagCategoryDao confOrderTagCategoryDao;

    @Override
    public List<ConfOrderTagCategory> listByQuery(ConfOrderTagCategoryQuery query) {
        List<ConfOrderTagCategory> confList = confOrderTagCategoryDao.listByQuery(query);
        return confList;
    }

    @Override
    public List<ConfOrderTagCategory> listPageByQuery(ConfOrderTagCategoryQuery query) {
        int count = confOrderTagCategoryDao.countByQuery(query);
        query.setTotalCount(count);
        List<ConfOrderTagCategory> confList = confOrderTagCategoryDao.listPageByQuery(query);
        return confList;
    }

    @Override
    public int countByQuery(ConfOrderTagCategoryQuery query) {
        return confOrderTagCategoryDao.countByQuery(query);
    }

    @Override
    public ConfOrderTagCategory findCategoryById(Integer id) {
        return confOrderTagCategoryDao.selectByPrimaryKey(id);
    }

    @Override
    public void updateCategoryById(ConfOrderTagCategory category) {
        Objects.requireNonNull(category.getCategId(), "ID不能为空");

        category.setUpdateTime(DateUtil.getNow());
        confOrderTagCategoryDao.updateByPrimaryKeySelective(category);
    }

    @Override
    public Integer insertCategory(ConfOrderTagCategory category) {
        category.setCreateTime(DateUtil.getNow());
        return confOrderTagCategoryDao.insertSelective(category);
    }

}
